package com.djmw.mouse.entity;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;

import com.djmw.mouse.service.constants.Constants;
import com.djmw.mouse.service.constants.Constants.City;
import com.djmw.mouse.service.constants.Constants.Province;

@Entity
@Table(name = "t_position")
public class Position extends IdEntity {
    public static final int STATUS_ENABLED = 0;
    public static final int STATUS_DISABLED = 1;
    public static final int STATUS_DELETED = 10;

    private Company company;
    private Department department;
    private String name;
    private String code;
    private int count;
    private int province;
    private int city;
    private int minAge;
    private int maxAge;
    private PositionType posType;
    private PositionType posType2;
    private int language;
    private int proficiency;
    private int language2;
    private int proficiency2;
    private int education;
    private int workingYears;
    private int major;
    private int major2;
    private int salaryRange;
    private int jobType;
    private String keyword;
    private String description;
    private String descriptionEng;
    private int order;
    private Date publishDate;
    private Date refreshDate;
    private Date closeDate;
    private int status;
    private double quota;
    private Timestamp lastModifiedDate;
    private Set<Application> application = new HashSet<Application>(0);
    private Set<Bookmark> bookmark = new HashSet<Bookmark>(0);
    private int promotionHomepage;

    public Position() {
    }

    public Position(Position pos) {
        this.id = pos.getId();
        this.company = pos.getCompany();
        this.department = pos.getDepartment();
        this.name = pos.getName();
        this.code = pos.getCode();
        this.count = pos.getCount();
        this.province = pos.getProvince();
        this.city = pos.getCity();
        this.minAge = pos.getMinAge();
        this.maxAge = pos.getMaxAge();
        this.posType = pos.getPosType();
        this.posType2 = pos.getPosType2();
        this.language = pos.getLanguage();
        this.proficiency = pos.getProficiency();
        this.language2 = pos.getLanguage2();
        this.proficiency2 = pos.getProficiency2();
        this.education = pos.getEducation();
        this.workingYears = pos.getWorkingYears();
        this.major = pos.getMajor();
        this.major2 = pos.getMajor2();
        this.salaryRange = pos.getSalaryRange();
        this.jobType = pos.getJobType();
        this.keyword = pos.getKeyword();
        this.description = pos.getDescription();
        this.descriptionEng = pos.getDescriptionEng();
        this.order = pos.getOrder();
        this.publishDate = pos.getPublishDate();
        this.refreshDate = pos.getRefreshDate();
        this.closeDate = pos.getCloseDate();
        this.status = pos.getStatus();
        this.quota = pos.getQuota();
        this.lastModifiedDate = pos.getLastModifiedDate();
    }

    @ManyToOne
    @JoinColumn(name = "c_company_id")
    public Company getCompany() {
        return company;
    }
    public void setCompany(Company company) {
        this.company = company;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.position", cascade = CascadeType.ALL)
    public Set<Application> getApplication() {
        return application;
    }
    public void setApplication(Set<Application> application) {
        this.application = application;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.position", cascade = CascadeType.ALL)
    public Set<Bookmark> getBookmark() {
        return bookmark;
    }
    public void setBookmark(Set<Bookmark> bookmark) {
        this.bookmark = bookmark;
    }

    @Range(min = 0)
    @Column(name = "c_order")
    public int getOrder() {
        return order;
    }
    public void setOrder(int order) {
        this.order = order;
    }

    @NotBlank
    @Column(name = "c_name")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    @ManyToOne
    @JoinColumn(name = "c_department_id")
    public Department getDepartment() {
        return department;
    }
    public void setDepartment(Department department) {
        this.department = department;
    }

    @Column(name = "c_code")
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }

    @Column(name = "c_count")
    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    @Column(name = "c_province")
    public int getProvince() {
        return province;
    }
    public void setProvince(int province) {
        this.province = province;
    }
    @Transient
    public String getProvinceName() {
        Province provinceObj = Constants.PROVINCES_MAP.get(province);
        return provinceObj == null ? "" : provinceObj.getName();
    }

    @Column(name = "c_city")
    public int getCity() {
        return city;
    }
    public void setCity(int city) {
        this.city = city;
    }
    @Transient
    public String getCityName() {
        City cityObj = Constants.CITIES_MAP.get(city);
        return cityObj == null ? "" : cityObj.getName();
    }

    @Column(name = "c_age_min")
    public int getMinAge() {
        return minAge;
    }
    public void setMinAge(int minAge) {
        this.minAge = minAge;
    }

    @Column(name = "c_age_max")
    public int getMaxAge() {
        return maxAge;
    }
    public void setMaxAge(int maxAge) {
        this.maxAge = maxAge;
    }

    @ManyToOne
    @JoinColumn(name = "c_position_type")
    public PositionType getPosType() {
        return posType;
    }
    public void setPosType(PositionType posType) {
        this.posType = posType;
    }

    @ManyToOne
    @JoinColumn(name = "c_position_type_2")
    public PositionType getPosType2() {
        return posType2;
    }
    public void setPosType2(PositionType posType2) {
        this.posType2 = posType2;
    }

    @Column(name = "c_lang")
    public int getLanguage() {
        return language;
    }
    public void setLanguage(int language) {
        this.language = language;
    }
    @Transient
    public String getLanguageName() {
        return language == 0 ? "" : Constants.LANGUAGES.get(language).getName();
    }

    @Column(name = "c_proficiency")
    public int getProficiency() {
        return proficiency;
    }
    public void setProficiency(int proficiency) {
        this.proficiency = proficiency;
    }
    @Transient
    public String getProficiencyName() {
        return proficiency == 0 ? "" : Constants.PROFICIENCYS.get(proficiency).getName();
    }

    @Column(name = "c_lang_2")
    public int getLanguage2() {
        return language2;
    }
    public void setLanguage2(int language2) {
        this.language2 = language2;
    }
    @Transient
    public String getLanguage2Name() {
        return language2 == 0 ? "" : Constants.LANGUAGES.get(language2).getName();
    }

    @Column(name = "c_proficiency_2")
    public int getProficiency2() {
        return proficiency2;
    }
    public void setProficiency2(int proficiency2) {
        this.proficiency2 = proficiency2;
    }
    @Transient
    public String getProficiency2Name() {
        return proficiency2 == 0 ? "" : Constants.PROFICIENCYS.get(proficiency2).getName();
    }

    @Column(name = "c_education")
    public int getEducation() {
        return education;
    }
    public void setEducation(int education) {
        this.education = education;
    }
    @Transient
    public String getEducationName() {
        return education == 0 ? "" : Constants.EDUCATIONS.get(education).getName();
    }

    @Column(name = "c_working_years")
    public int getWorkingYears() {
        return workingYears;
    }
    public void setWorkingYears(int workingYears) {
        this.workingYears = workingYears;
    }
    @Transient
    public String getWorkingYearsName() {
        return workingYears == 0 ? "" : Constants.WORKING_YEARS_MEMBER.get(workingYears).getName();
    }

    @Column(name = "c_major")
    public int getMajor() {
        return major;
    }
    public void setMajor(int major) {
        this.major = major;
    }
    @Transient
    public String getMajorName() {
        return major == 0 ? "" : Constants.MAJORS.get(major).getName();
    }

    @Column(name = "c_major2")
    public int getMajor2() {
        return major2;
    }
    public void setMajor2(int major) {
        this.major2 = major;
    }
    @Transient
    public String getMajor2Name() {
        return major2 == 0 ? "" : Constants.MAJORS.get(major2).getName();
    }

    @Column(name = "c_salary_range")
    public int getSalaryRange() {
        return salaryRange;
    }
    public void setSalaryRange(int salaryRange) {
        this.salaryRange = salaryRange;
    }
    @Transient
    public String getSalaryRangeName() {
        return salaryRange == 0 ? "" : Constants.SALARY_RANGES.get(salaryRange).getName();
    }

    @Column(name = "c_type")
    public int getJobType() {
        return jobType;
    }
    public void setJobType(int jobType) {
        this.jobType = jobType;
    }
    @Transient
    public String getJobTypeName() {
        return jobType == 0 ? "" : Constants.JOB_TYPES.get(jobType).getName();
    }

    @Column(name = "c_keywords")
    public String getKeyword() {
        return keyword;
    }
    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    @Column(name = "c_description")
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name = "c_description_eng")
    public String getDescriptionEng() {
        return descriptionEng;
    }
    public void setDescriptionEng(String descriptionEng) {
        this.descriptionEng = descriptionEng;
    }

    @Column(name = "c_publish_date")
    public Date getPublishDate() {
        return publishDate;
    }
    public void setPublishDate(Date publishDate) {
        this.publishDate = publishDate;
    }

    @Column(name = "c_refresh_date")
    public Date getRefreshDate() {
        return refreshDate;
    }
    public void setRefreshDate(Date refreshDate) {
        this.refreshDate = refreshDate;
    }

    @Column(name = "c_close_date")
    public Date getCloseDate() {
        return closeDate;
    }
    public void setCloseDate(Date closeDate) {
        this.closeDate = closeDate;
    }

    @Column(name = "c_status")
    public int getStatus() {
        return status;
    }
    public void setStatus(int status) {
        this.status = status;
    }

    @Column(name = "c_quota")
    public double getQuota() {
        return quota;
    }
    public void setQuota(double quota) {
        this.quota = quota;
    }

    @Column(name = "c_last_modified_date")
    public Timestamp getLastModifiedDate() {
        return lastModifiedDate;
    }
    public void setLastModifiedDate(Timestamp lastModifiedDate) {
        this.lastModifiedDate = lastModifiedDate;
    }

    @Transient
    public Long getDepartmentId() {
        return department == null ? null : department.getId();
    }

    @Column(name = "c_promotion_homepage")
    public int getPromotionHomepage() {
        return promotionHomepage;
    }

    public void setPromotionHomepage(int promotionHomepage) {
        this.promotionHomepage = promotionHomepage;
    }
}
